#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2020, Pavel Pletenev
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
    module.name = ":board:stm32_f4ve"
    module.description = """\
# STM32_F4VE

https://stm32-base.org/boards/STM32F407VET6-STM32-F4VE-V2.0.html
"""

def prepare(module, options):
    if not options[":target"].partname.startswith("stm32f407vet6"):
        return False

    module.depends(
        ":architecture:clock",
        ":debug",
        ":platform:clock",
        ":platform:core",
        ":platform:gpio",
        ":platform:uart:1",
        ":platform:fsmc",
        ":platform:spi:1",
        ":platform:spi:2",
        ":driver:block.device:spi.flash",
        ":driver:ads7843")
    return True

def build(env):
    env.outbasepath = "modm/src/modm/board"
    env.substitutions = {
        "with_logger": True,
        "with_assert": env.has_module(":architecture:assert")
    }
    env.template("../board.cpp.in", "board.cpp")
    env.copy('.')

    env.outbasepath = "modm/openocd/modm/board/"
    env.copy(repopath("tools/openocd/modm/stm32f4x.cfg"), "stm32f4x.cfg")
    env.copy(repopath("tools/openocd/modm/stm32_f4ve.cfg"), "stm32_f4ve.cfg")
    env.collect(":build:openocd.source", "modm/board/stm32_f4ve.cfg")
